package com.ld.common.util.notice.plugin;

import com.ld.common.plugin.Plugin;
import com.ld.common.plugin.PluginInfo;
import com.ld.common.util.notice.NoticeManager;
import com.ld.common.util.notice.NoticeModel;
import com.ld.shieldsb.common.core.model.Result;
import com.ld.shieldsb.common.core.util.StringUtils;
import com.ld.shieldsb.common.core.util.notice.sms.SMSUtil;

public class SMSNoticeUtil implements Plugin {
    private PluginInfo pluginInfo = new PluginInfo("短信通知插件", this); // 插件信息
    public static final String NOTICE_TYPE = "SMSNotice";

    public static final NoticeModel NOTICE = new NoticeModel("短信通知", NOTICE_TYPE) {

        @Override
        public Result notice(String signName, String sendTo, String subject, String content, Object otherParams) {
            if (content.length() > 100) { // 字数太多进行截取
                content = content.substring(0, 100) + "……";
            }
            if (StringUtils.isBlank(signName)) {
                signName = "绿盾项目组"; // TODO 动态化
            }
            Result smsResult = SMSUtil.sendSMS(-1, sendTo, subject + ":" + content, signName, false);
            return smsResult;
        }

    }; // menus缓存

    @Override
    public void initializePlugin() {
        NoticeManager.register(NOTICE); // 注册到消息通知管理器中

    }

    @Override
    public void destroyPlugin() {

    }

    @Override
    public PluginInfo getPluginInfo() {
        return pluginInfo;
    }

}
